package com.quanyan.assets.service.impl;

import com.quanyan.api.APIRequest;
import com.quanyan.api.APIResponse;
import com.quanyan.api.enums.ApiResponseEnum;
import com.quanyan.api.enums.AssetsPayReceive;
import com.quanyan.api.enums.AssetsType;
import com.quanyan.assets.constants.AssetsConstants;
import com.quanyan.assets.emun.*;
import com.quanyan.assets.entity.*;
import com.quanyan.assets.entity.vo.AssetsRuleVo;
import com.quanyan.assets.enums.CouponOrderType;
import com.quanyan.assets.enums.CouponStatus;
import com.quanyan.assets.enums.SportType;
import com.quanyan.assets.mapper.*;
import com.quanyan.assets.repository.AccumulateRuleRepository;
import com.quanyan.assets.repository.EggsAccumulateHistoryRepository;
import com.quanyan.assets.repository.ShellAccumulateHistoryRepository;
import com.quanyan.assets.repository.UserAssetsRepository;
import com.quanyan.assets.request.*;
import com.quanyan.assets.response.RespCoupon;
import com.quanyan.assets.response.RespRuleDetail;
import com.quanyan.assets.response.RespUserAccumulateModify;
import com.quanyan.assets.service.*;
import com.quanyan.assets.web.TestController;
import com.quanyan.common.Plugin.PageObj;
import com.quanyan.common.constants.Constants;
import com.quanyan.common.enums.BaseEnum;
import com.quanyan.common.exception.BizException;
import com.quanyan.common.utils.CommonUtils;
import com.quanyan.common.utils.GsonUtils;
import com.quanyan.user.response.RespUserInfoBase;
import com.quanyan.user.serviceFacade.UserServiceFacade;
import org.apache.commons.beanutils.BeanUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import javax.validation.Valid;
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created by wmb on 2016/5/31.
 */
@Service("userAssetsService")
public class UserAssetsServiceImpl implements UserAssetsService {
    private static final Logger log = LoggerFactory.getLogger(UserAssetsService.class);
    @Autowired
    private TbUserAssetsMapper tbUserAssetsMapper;
    @Autowired
    private ETbUserAssetsMapper etbUserAssetsMapper;
    @Autowired
    private TbUserEggsAccumulateHistoryMapper tbUserEggsAccumulateHistoryMapper;
    @Autowired
    private TbAccumulateRuleMapper tbAccumulateRuleMapper;
    @Autowired
    private TbUserShellAccumulateHistoryMapper tbUserShellAccumulateHistoryMapper;
    @Autowired
    private UtilAssetsRuleService utilAssetsRuleService;
    @Autowired
    private CurrencyService currencyService;
    @Autowired
    private EggsAccumulateHistoryRepository eggsAccumulateHistoryRepository;
    @Autowired
    private ShellAccumulateHistoryRepository shellAccumulateHistoryRepository;
    @Autowired
    private UserAssetsRepository userAssetsRepository;
    @Autowired
    private AccumulateRuleRepository accumulateRuleRepository;
    @Autowired
    private UserServiceFacade userServiceFacade;
    @Autowired
    private CouponService couponService;
    @Autowired
    private UtilAccumulateService utilAccumulateService;
    @Autowired
    private UtilCouponService utilCouponService;
    @Autowired
    private ETbUserEggsAccumulateHistoryMapper eTbUserEggsAccumulateHistoryMapper;
    private Logger logger = LoggerFactory.getLogger(UserAssetsService.class);

    @Override
    @Transactional(rollbackFor = Exception.class)
    @Valid
    public APIResponse add(APIRequest<ReqUserAssets> apiRequest) {
        ReqUserAssets reqUserAssets = apiRequest.getData();
        //新增该系统下该用户的所有资产
        userAssetsRepository.initAllCount(reqUserAssets.getUid());
        return APIResponse.returnSuccess(ApiResponseEnum.SUCCESS);
    }

    @Override
    @Valid
    @Transactional(rollbackFor = Exception.class,isolation = Isolation.READ_COMMITTED)
    //修改积分
    public APIResponse<RespUserAccumulateModify> modifyAccumulate(APIRequest<ReqUserAccumulateModify> apiRequest) {
        ReqUserAccumulateModify reqUserAccumulateModify = apiRequest.getData();
        reqUserAccumulateModify.setStatus(StatusType.EFFECTIVE.id.byteValue());
        //修改或冻结积分
        return modifyOrFreezeAccumulate(reqUserAccumulateModify);
    }

    @Override
    @Valid
    @Transactional(rollbackFor = Exception.class)
    //冻结积分
    public APIResponse<RespUserAccumulateModify> freezeAccumulate(APIRequest<ReqUserAccumulateModify> apiRequest) {
        ReqUserAccumulateModify reqUserAccumulateModify = apiRequest.getData();
        reqUserAccumulateModify.setStatus(StatusType.FREEZE.id.byteValue());
        //修改或冻结积分
        return modifyOrFreezeAccumulate(reqUserAccumulateModify);
    }

    private APIResponse<RespUserAccumulateModify> modifyOrFreezeAccumulate(ReqUserAccumulateModify reqUserAccumulateModify) {
        //判断systemCode+businessCode+assetsType是否存在
        TbAccumulateRuleExample tbAccumulateRuleExample = new TbAccumulateRuleExample();
        tbAccumulateRuleExample.createCriteria().andSystemCodeEqualTo(reqUserAccumulateModify.getSystemCode())
                .andBusinessCodeEqualTo(reqUserAccumulateModify.getBusinessCode())
                .andAssetsTypeEqualTo(reqUserAccumulateModify.getAssetsType()).andStateEqualTo(StateType.EFFECTIVE.id.byteValue());
        List<TbAccumulateRule> tbAccumulateRuleList = tbAccumulateRuleMapper.selectByExample(tbAccumulateRuleExample);
        if (tbAccumulateRuleList.isEmpty()) {
            throw new BizException(AssetsErrorEnum.ASSETS_RULE_RECORD_DO_NOT_EXISTS);
        }else{
            reqUserAccumulateModify.setDescribe(tbAccumulateRuleList.get(0).getpDescribe());
        }
        //通过该业务获取积分数
        AssetsRuleVo assetsRuleVo = new AssetsRuleVo();
        try {
            BeanUtils.copyProperties(assetsRuleVo, tbAccumulateRuleList.get(0));
        } catch (InvocationTargetException e) {
            throw new BizException(AssetsErrorEnum.COPY_PROPERTY_ERROR);
        } catch (IllegalAccessException e) {
            throw new BizException(AssetsErrorEnum.COPY_PROPERTY_ERROR);
        }
        assetsRuleVo.setOrderAmount(reqUserAccumulateModify.getOrderAmount());
        assetsRuleVo.setUid(reqUserAccumulateModify.getUid());
        assetsRuleVo.setAccumulate(reqUserAccumulateModify.getAccumulate());
        assetsRuleVo.setBusinessNo(reqUserAccumulateModify.getBusinessNo());
        Long accumulate = utilAssetsRuleService.getAccumulateByRule(assetsRuleVo);
        //消费积分时如果有传积分判断积分是否小于规则计算大于0的，不传就按规则计算
        if (tbAccumulateRuleList.get(0).getOpType() == OpType.CONSUME.id.byteValue() && null != reqUserAccumulateModify.getAccumulate()
                && reqUserAccumulateModify.getAccumulate() < accumulate && reqUserAccumulateModify.getAccumulate() > 0) {
            accumulate = reqUserAccumulateModify.getAccumulate();
        }else if(tbAccumulateRuleList.get(0).getOpType() == OpType.CONSUME.id.byteValue() && null != reqUserAccumulateModify.getAccumulate()
                && reqUserAccumulateModify.getAccumulate() > accumulate){
            throw new BizException(AssetsErrorEnum.ACCUMULATE_IS_INVALID);
        }
        //最终扣的积分
        reqUserAccumulateModify.setAccumulate(accumulate);
        if (tbAccumulateRuleList.get(0).getOpType() == OpType.CONSUME.id.byteValue()) {
            if(assetsRuleVo.getRuleType() == 2 && null == assetsRuleVo.getBusinessNo()){
                //下单订单号必传
                throw new BizException(AssetsErrorEnum.BUSINESS_NO_NULL);
            }
            accumulate = -accumulate;
        }
        //判断该账号是否存在，不存在就初始化
        userAssetsRepository.selectByUidAndAssetsType(reqUserAccumulateModify.getUid(), reqUserAccumulateModify.getAssetsType());
        //通过状态相应处理
        ReqUserAccumulateModifyBatch reqUserAccumulateModifyBatch = new ReqUserAccumulateModifyBatch();
        try {
            BeanUtils.copyProperties(reqUserAccumulateModifyBatch, reqUserAccumulateModify);
        } catch (InvocationTargetException e) {
            throw new BizException(AssetsErrorEnum.COPY_PROPERTY_ERROR);
        } catch (IllegalAccessException e) {
            throw new BizException(AssetsErrorEnum.COPY_PROPERTY_ERROR);
        }
        AccumulateAssets accumulateAssets = new AccumulateAssets();
        accumulateAssets.setAssetsType(reqUserAccumulateModify.getAssetsType());
        accumulateAssets.setAccumulate(reqUserAccumulateModify.getAccumulate());
        RespUserAccumulateModify respUserAccumulateModify = dealAccumulateByStatus(reqUserAccumulateModifyBatch, accumulateAssets, accumulate);
        return APIResponse.returnSuccess(respUserAccumulateModify);
    }

    @Override
    @Valid
    @Transactional(rollbackFor = Exception.class,isolation = Isolation.READ_COMMITTED)
    public APIResponse<List<RespUserAccumulateModify>> modifyAccumulateBatch(APIRequest<ReqUserAccumulateModifyBatch> apiRequest) {
        ReqUserAccumulateModifyBatch reqUserAccumulateModifyBatch = apiRequest.getData();
        //批量修改
        reqUserAccumulateModifyBatch.setStatus(StatusType.EFFECTIVE.id.byteValue());
        return modifyOrFreezeAccumulateBatch(reqUserAccumulateModifyBatch);
    }

    @Override
    @Valid
    @Transactional(rollbackFor = Exception.class)
    public APIResponse<List<RespUserAccumulateModify>> freezeAccumulateBatch(APIRequest<ReqUserAccumulateModifyBatch> apiRequest) {
        ReqUserAccumulateModifyBatch reqUserAccumulateModifyBatch = apiRequest.getData();
        //批量冻结
        reqUserAccumulateModifyBatch.setStatus(StatusType.FREEZE.id.byteValue());
        return modifyOrFreezeAccumulateBatch(reqUserAccumulateModifyBatch);
    }

    private APIResponse<List<RespUserAccumulateModify>> modifyOrFreezeAccumulateBatch(ReqUserAccumulateModifyBatch reqUserAccumulateModifyBatch) {
        List<RespUserAccumulateModify> respUserAccumulateModifyList = new ArrayList<RespUserAccumulateModify>();
        for (AccumulateAssets accumulateAssets : reqUserAccumulateModifyBatch.getAccumulateAssetsList()) {
            //判断systemCode+businessCode+assetsType是否存在
            TbAccumulateRuleExample tbAccumulateRuleExample = new TbAccumulateRuleExample();
            tbAccumulateRuleExample.createCriteria().andSystemCodeEqualTo(reqUserAccumulateModifyBatch.getSystemCode())
                    .andBusinessCodeEqualTo(reqUserAccumulateModifyBatch.getBusinessCode())
                    .andAssetsTypeEqualTo(accumulateAssets.getAssetsType());
            List<TbAccumulateRule> tbAccumulateRuleList = tbAccumulateRuleMapper.selectByExample(tbAccumulateRuleExample);
            if (tbAccumulateRuleList.isEmpty()) {
                throw new BizException(AssetsErrorEnum.ASSETS_RULE_RECORD_DO_NOT_EXISTS);
            }else {
                reqUserAccumulateModifyBatch.setDescribe(tbAccumulateRuleList.get(0).getpDescribe());
            }
            //通过该业务获取积分数
            AssetsRuleVo assetsRuleVo = new AssetsRuleVo();
            try {
                BeanUtils.copyProperties(assetsRuleVo, tbAccumulateRuleList.get(0));
            } catch (InvocationTargetException e) {
                throw new BizException(AssetsErrorEnum.COPY_PROPERTY_ERROR);
            } catch (IllegalAccessException e) {
                throw new BizException(AssetsErrorEnum.COPY_PROPERTY_ERROR);
            }
            assetsRuleVo.setOrderAmount(reqUserAccumulateModifyBatch.getOrderAmount());
            assetsRuleVo.setUid(reqUserAccumulateModifyBatch.getUid());
            assetsRuleVo.setAccumulate(accumulateAssets.getAccumulate());
            Long accumulate = utilAssetsRuleService.getAccumulateByRule(assetsRuleVo);
            //消费积分时如果有传积分判断积分是否小于规则计算大于0的，不传就按规则计算
            if (tbAccumulateRuleList.get(0).getOpType() == OpType.CONSUME.id.byteValue() && null != accumulateAssets.getAccumulate()
                    && accumulateAssets.getAccumulate() < accumulate && accumulateAssets.getAccumulate() > 0) {
                accumulate = accumulateAssets.getAccumulate();
            }
            //最终扣的积分
            accumulateAssets.setAccumulate(accumulate);
            if (tbAccumulateRuleList.get(0).getOpType() == OpType.CONSUME.id.byteValue()) {
                accumulate = -accumulate;
            }
            //判断该账号是否存在，不存在就初始化
            userAssetsRepository.selectByUidAndAssetsType(reqUserAccumulateModifyBatch.getUid(), accumulateAssets.getAssetsType());
            //通过状态相应处理
            RespUserAccumulateModify respUserAccumulateModify = dealAccumulateByStatus(reqUserAccumulateModifyBatch, accumulateAssets, accumulate);
            respUserAccumulateModifyList.add(respUserAccumulateModify);
        }
        return APIResponse.returnSuccess(respUserAccumulateModifyList);
    }

    private RespUserAccumulateModify dealAccumulateByStatus(ReqUserAccumulateModifyBatch reqUserAccumulateModifyBatch, AccumulateAssets accumulateAssets, Long accumulate) {
        //修改
        if (reqUserAccumulateModifyBatch.getStatus() == StatusType.EFFECTIVE.id.byteValue()) {
            //更新个人积分
            int count = etbUserAssetsMapper.updateEffectiveAccumulate(reqUserAccumulateModifyBatch.getUid(), accumulateAssets.getAssetsType(), accumulate);
            if (count == 0) {
                //todo 日志处理
                //抵扣失败
                throw new BizException(AssetsErrorEnum.USER_ACCUMULATE_NOT_ENOUGH);
            } else {
                TbUserAssetsExample tbUserAssetsExample = new TbUserAssetsExample();
                tbUserAssetsExample.createCriteria().andUidEqualTo(reqUserAccumulateModifyBatch.getUid()).andAssetsTypeEqualTo(accumulateAssets.getAssetsType());
                List<TbUserAssets> tbUserAssetsList = tbUserAssetsMapper.selectByExample(tbUserAssetsExample);
                //抵扣成功添加积分记录
                insertAccumulateHistory(accumulate < 0 ? (byte) 0 : (byte) 1, reqUserAccumulateModifyBatch, accumulateAssets);
                RespUserAccumulateModify respUserAccumulateModify = new RespUserAccumulateModify();
                respUserAccumulateModify.setAccount(tbUserAssetsList.get(0));
                respUserAccumulateModify.setAccumulate(accumulateAssets.getAccumulate());
                return respUserAccumulateModify;
            }
        }
        //冻结
        else if (reqUserAccumulateModifyBatch.getStatus() == StatusType.FREEZE.id.byteValue()) {
            //如果之前已经冻结的则直接返回
            if(accumulateAssets.getAssetsType().byteValue()==AssetsType.ASSETS_EGGS.id.byteValue()){
                TbUserEggsAccumulateHistoryExample tbUserEggsAccumulateHistoryExample=new TbUserEggsAccumulateHistoryExample();
                tbUserEggsAccumulateHistoryExample.createCriteria().andSystemCodeEqualTo(reqUserAccumulateModifyBatch.getSystemCode())
                        .andBusinessCodeEqualTo(reqUserAccumulateModifyBatch.getBusinessCode()).andBusinessNoEqualTo(reqUserAccumulateModifyBatch.getBusinessNo())
                        .andOpTypeEqualTo(OpType.CONSUME.id.byteValue()).andStatusEqualTo(StatusType.FREEZE.id.byteValue());
                List<TbUserEggsAccumulateHistory> tbUserEggsAccumulateHistoryList=tbUserEggsAccumulateHistoryMapper.selectByExample(tbUserEggsAccumulateHistoryExample);
                if(!tbUserEggsAccumulateHistoryList.isEmpty()){
                    TbUserAssets tbUserAssets = userAssetsRepository.selectByUidAndAssetsType(tbUserEggsAccumulateHistoryList.get(0).getUid(), accumulateAssets.getAssetsType());
                    RespUserAccumulateModify respUserAccumulateModify = new RespUserAccumulateModify();
                    respUserAccumulateModify.setAccount(tbUserAssets);
                    respUserAccumulateModify.setAccumulate(tbUserEggsAccumulateHistoryList.get(0).getAccumulate());
                    return respUserAccumulateModify;
                }else{
                    tbUserEggsAccumulateHistoryExample.clear();
                    tbUserEggsAccumulateHistoryExample.createCriteria().andSystemCodeEqualTo(reqUserAccumulateModifyBatch.getSystemCode())
                            .andBusinessCodeEqualTo(reqUserAccumulateModifyBatch.getBusinessCode()).andBusinessNoEqualTo(reqUserAccumulateModifyBatch.getBusinessNo());
                    List<TbUserEggsAccumulateHistory> tbUserEggsAccumulateHistoryList1=tbUserEggsAccumulateHistoryMapper.selectByExample(tbUserEggsAccumulateHistoryExample);
                    if(!tbUserEggsAccumulateHistoryList1.isEmpty()){
                        throw new BizException(AssetsErrorEnum.BUSINESS_NO_IS_EXIST);
                    }
                }
            }else{
                TbUserShellAccumulateHistoryExample tbUserShellAccumulateHistoryExample=new TbUserShellAccumulateHistoryExample();
                tbUserShellAccumulateHistoryExample.createCriteria().andSystemCodeEqualTo(reqUserAccumulateModifyBatch.getSystemCode())
                        .andBusinessCodeEqualTo(reqUserAccumulateModifyBatch.getBusinessCode()).andBusinessNoEqualTo(reqUserAccumulateModifyBatch.getBusinessNo())
                        .andOpTypeEqualTo(OpType.CONSUME.id.byteValue()).andStatusEqualTo(StatusType.FREEZE.id.byteValue());
                List<TbUserShellAccumulateHistory> tbUserShellAccumulateHistoryList=tbUserShellAccumulateHistoryMapper.selectByExample(tbUserShellAccumulateHistoryExample);
                if (!tbUserShellAccumulateHistoryList.isEmpty()) {
                    TbUserAssets tbUserAssets = userAssetsRepository.selectByUidAndAssetsType(tbUserShellAccumulateHistoryList.get(0).getUid(), accumulateAssets.getAssetsType());
                    RespUserAccumulateModify respUserAccumulateModify = new RespUserAccumulateModify();
                    respUserAccumulateModify.setAccount(tbUserAssets);
                    respUserAccumulateModify.setAccumulate(tbUserShellAccumulateHistoryList.get(0).getAccumulate());
                    return respUserAccumulateModify;
                }else{
                    tbUserShellAccumulateHistoryExample.clear();
                    tbUserShellAccumulateHistoryExample.createCriteria().andSystemCodeEqualTo(reqUserAccumulateModifyBatch.getSystemCode())
                            .andBusinessCodeEqualTo(reqUserAccumulateModifyBatch.getBusinessCode()).andBusinessNoEqualTo(reqUserAccumulateModifyBatch.getBusinessNo());
                    List<TbUserShellAccumulateHistory> tbUserShellAccumulateHistoryList1=tbUserShellAccumulateHistoryMapper.selectByExample(tbUserShellAccumulateHistoryExample);
                    if(!tbUserShellAccumulateHistoryList1.isEmpty()){
                        throw new BizException(AssetsErrorEnum.BUSINESS_NO_IS_EXIST);
                    }
                }
            }
            int count = etbUserAssetsMapper.updateFreezeAccumulate(reqUserAccumulateModifyBatch.getUid(), accumulateAssets.getAssetsType(), accumulate);
            if (count == 0) {
                //todo 日志处理
                //抵扣失败
                throw new BizException(AssetsErrorEnum.USER_ACCUMULATE_NOT_ENOUGH);
            } else {
                TbUserAssets tbUserAssets = userAssetsRepository.selectByUidAndAssetsType(reqUserAccumulateModifyBatch.getUid(), accumulateAssets.getAssetsType());
                //抵扣成功添加积分记录
                insertAccumulateHistory(accumulate < 0 ? (byte) 0 : (byte) 1, reqUserAccumulateModifyBatch, accumulateAssets);
                RespUserAccumulateModify respUserAccumulateModify = new RespUserAccumulateModify();
                respUserAccumulateModify.setAccount(tbUserAssets);
                respUserAccumulateModify.setAccumulate(accumulateAssets.getAccumulate());
                return respUserAccumulateModify;
            }
        } else {
            throw new BizException(AssetsErrorEnum.STATUS_IS_INVALID);
        }
    }


    @Override
    @Valid
    public APIResponse<List<RespRuleDetail>> getUserAccumulateAndRule(APIRequest<ReqRuleDetail> apiRequest) {
        ReqRuleDetail reqRuleDetail = apiRequest.getData();
        //获取该系统该业务下的所有规则
        TbAccumulateRuleExample tbAccumulateRuleExample = new TbAccumulateRuleExample();
        TbAccumulateRuleExample.Criteria criteria = tbAccumulateRuleExample.createCriteria();
        criteria.andSystemCodeEqualTo(reqRuleDetail.getSystemCode());
        criteria.andBusinessCodeEqualTo(reqRuleDetail.getBusinessCode());
        if (null != reqRuleDetail.getAssetsType()) {
            criteria.andAssetsTypeEqualTo(reqRuleDetail.getAssetsType());
        }
        List<TbAccumulateRule> tbAccumulateRuleList = tbAccumulateRuleMapper.selectByExample(tbAccumulateRuleExample);
        if (tbAccumulateRuleList.isEmpty()) {
            throw new BizException(AssetsErrorEnum.ASSETS_RULE_RECORD_DO_NOT_EXISTS);
        }
        List<RespRuleDetail> respRuleDetailList = new ArrayList<RespRuleDetail>();
        for (TbAccumulateRule tbAccumulateRule : tbAccumulateRuleList) {
            RespRuleDetail respRuleDetail = new RespRuleDetail();
            //获取用户该系统该资产类型对象
            TbUserAssetsExample tbUserAssetsExample = new TbUserAssetsExample();
            tbUserAssetsExample.createCriteria().andUidEqualTo(reqRuleDetail.getUid())
                    .andAssetsTypeEqualTo(tbAccumulateRule.getAssetsType());
            List<TbUserAssets> tbUserAssetsList = tbUserAssetsMapper.selectByExample(tbUserAssetsExample);
            if (tbUserAssetsList.isEmpty()) {
                TbUserAssets tbUserAssets = new TbUserAssets();
                tbUserAssets.setUid(reqRuleDetail.getUid());
                tbUserAssets.setAssetsType(tbAccumulateRule.getAssetsType());
                tbUserAssets.setAccumulate(0L);
                tbUserAssets.setState(StateType.EFFECTIVE.id.byteValue());
                try {
                    tbUserAssetsMapper.insertSelective(tbUserAssets);
                    tbUserAssetsList.add(tbUserAssets);
                } catch (Exception e) {
                    System.out.println(e.getMessage());
                }
            }
            respRuleDetail.setAccount(tbUserAssetsList.get(0));
            //积分规则
            respRuleDetail.setAccumulateRule(tbAccumulateRuleList.get(0).getAccumulateRule());
            AssetsRuleVo assetsRuleVo = new AssetsRuleVo();
            try {
                BeanUtils.copyProperties(assetsRuleVo, tbAccumulateRuleList.get(0));
            } catch (InvocationTargetException e) {
                throw new BizException(AssetsErrorEnum.COPY_PROPERTY_ERROR);
            } catch (IllegalAccessException e) {
                throw new BizException(AssetsErrorEnum.COPY_PROPERTY_ERROR);
            }
            assetsRuleVo.setOrderAmount(reqRuleDetail.getOrderAmount());
            assetsRuleVo.setUid(reqRuleDetail.getUid());
            //根据规则获得获取（抵扣）积分数
            //通过该业务获取积分数
            Long accumulate = utilAssetsRuleService.getAccumulateByRule(assetsRuleVo);
            //判断积分数是否大于等于账号积分数
            if (accumulate > tbUserAssetsList.get(0).getAccumulate()) {
                accumulate = tbUserAssetsList.get(0).getAccumulate();
            }
            //最终可用积分数
            respRuleDetail.setUseAccumulate(accumulate);

            //兑换成RMB
            respRuleDetail.setExchangeRMB(currencyService.exchangeRatioById(tbAccumulateRuleList.get(0).getAssetsType()).getData().multiply(new BigDecimal(accumulate)));
            respRuleDetailList.add(respRuleDetail);

        }
        return APIResponse.returnSuccess(respRuleDetailList);
    }

    @Override
    @Valid
    @Transactional(rollbackFor = Exception.class)
    public APIResponse<List<TbUserAssets>> unfreezeAccumulateSuccess(APIRequest<ReqUnfreeze> apiRequest) {
        //同个订单所有资产类型冻结状态一致
        ReqUnfreeze reqUnfreeze = apiRequest.getData();
        //解冻成功(支付成功)
        reqUnfreeze.setStatus(StatusType.EFFECTIVE.id.byteValue());
        return unfreezeAccumulate(reqUnfreeze);

    }

    @Override
    @Valid
    @Transactional(rollbackFor = Exception.class)
    public APIResponse<List<TbUserAssets>> unfreezeAccumulateFail(APIRequest<ReqUnfreeze> apiRequest) {
        //同个订单所有资产类型冻结状态一致
        ReqUnfreeze reqUnfreeze = apiRequest.getData();
        //解冻失败(支付失败)
        reqUnfreeze.setStatus(StatusType.DISABLE.id.byteValue());
        return unfreezeAccumulate(reqUnfreeze);

    }

    private APIResponse<List<TbUserAssets>> unfreezeAccumulate(ReqUnfreeze reqUnfreeze) {
        List<TbUserAssets> tbUserAssetsList = new ArrayList<TbUserAssets>();
        for (AssetsType assetsType : AssetsType.values()) {
            //鸟蛋
            if (assetsType == AssetsType.ASSETS_EGGS) {
                //更新历史状态
                int updateHistory = eggsAccumulateHistoryRepository.updateFreezeStatus(reqUnfreeze);
                if (updateHistory > 1) {
                    throw new BizException(AssetsErrorEnum.UNFREEZE_NOT_ONLY);
                } else if (updateHistory == 1) {
                    TbUserEggsAccumulateHistory tbUserEggsAccumulateHistory = eggsAccumulateHistoryRepository.selectFreeze(reqUnfreeze);
                    //解冻个人积分
                    int count = etbUserAssetsMapper.updateUnfreezeAccumulate(tbUserEggsAccumulateHistory.getUid(), AssetsType.ASSETS_EGGS.id.byteValue(), tbUserEggsAccumulateHistory.getAccumulate(), reqUnfreeze.getStatus());
                    //修改历史记录
                    if (count == 1) {
                        //获取当前用户该资产
                        TbUserAssets tbUserAssets = userAssetsRepository.selectByUidAndAssetsType(tbUserEggsAccumulateHistory.getUid(), AssetsType.ASSETS_EGGS.id.byteValue());
                        tbUserAssetsList.add(tbUserAssets);
                    }else{
                        //解冻个人积分异常回滚
                        throw new BizException(AssetsErrorEnum.UNFREEZE_USER_ACCUMULATE_FAIL);
                    }
                } else {
                    //之前如果有解冻直接返回
                    TbUserEggsAccumulateHistoryExample tbUserEggsAccumulateHistoryExample=new TbUserEggsAccumulateHistoryExample();
                    tbUserEggsAccumulateHistoryExample.createCriteria().andSystemCodeEqualTo(reqUnfreeze.getSystemCode())
                            .andBusinessCodeEqualTo(reqUnfreeze.getBusinessCode()).andBusinessNoEqualTo(reqUnfreeze.getBusinessNo())
                            .andOpTypeEqualTo(OpType.CONSUME.id.byteValue()).andStatusEqualTo(reqUnfreeze.getStatus());
                    List<TbUserEggsAccumulateHistory> tbUserEggsAccumulateHistoryList=tbUserEggsAccumulateHistoryMapper.selectByExample(tbUserEggsAccumulateHistoryExample);
                    if (!tbUserEggsAccumulateHistoryList.isEmpty()) {
                        TbUserAssets tbUserAssets = userAssetsRepository.selectByUidAndAssetsType(tbUserEggsAccumulateHistoryList.get(0).getUid(), AssetsType.ASSETS_EGGS.id.byteValue());
                        tbUserAssetsList.add(tbUserAssets);
                    }
                }
            }
            //蛋壳
            if (assetsType == AssetsType.ASSETS_SHELL) {
                //更新历史状态
                int updateHistory = shellAccumulateHistoryRepository.updateFreezeStatus(reqUnfreeze);
                if (updateHistory > 1) {
                    throw new BizException(AssetsErrorEnum.UNFREEZE_NOT_ONLY);
                } else if (updateHistory == 1) {
                    TbUserShellAccumulateHistory tbUserShellAccumulateHistory = shellAccumulateHistoryRepository.selectFreeze(reqUnfreeze);

                    //解冻个人积分
                    int count = etbUserAssetsMapper.updateUnfreezeAccumulate(tbUserShellAccumulateHistory.getUid(), AssetsType.ASSETS_SHELL.id.byteValue(), tbUserShellAccumulateHistory.getAccumulate(), reqUnfreeze.getStatus());
                    //修改历史记录
                    if (count != 0) {
                        //获取当前用户该资产
                        TbUserAssets tbUserAssets = userAssetsRepository.selectByUidAndAssetsType(tbUserShellAccumulateHistory.getUid(), AssetsType.ASSETS_SHELL.id.byteValue());
                        tbUserAssetsList.add(tbUserAssets);
                    }
                }else {
                    TbUserShellAccumulateHistoryExample tbUserShellAccumulateHistoryExample=new TbUserShellAccumulateHistoryExample();
                    tbUserShellAccumulateHistoryExample.createCriteria().andSystemCodeEqualTo(reqUnfreeze.getSystemCode())
                            .andBusinessCodeEqualTo(reqUnfreeze.getBusinessCode()).andBusinessNoEqualTo(reqUnfreeze.getBusinessNo())
                            .andOpTypeEqualTo(OpType.CONSUME.id.byteValue()).andStatusEqualTo(reqUnfreeze.getStatus());
                    List<TbUserShellAccumulateHistory> tbUserShellAccumulateHistoryList=tbUserShellAccumulateHistoryMapper.selectByExample(tbUserShellAccumulateHistoryExample);
                    if (!tbUserShellAccumulateHistoryList.isEmpty()) {
                        TbUserAssets tbUserAssets = userAssetsRepository.selectByUidAndAssetsType(tbUserShellAccumulateHistoryList.get(0).getUid(), AssetsType.ASSETS_EGGS.id.byteValue());
                        tbUserAssetsList.add(tbUserAssets);
                    }
                }
            }
        }
        return APIResponse.returnSuccess(tbUserAssetsList);
    }

    @Override
    @Valid
    public APIResponse<List<TbUserAssets>> getUserAccumulateList(APIRequest<ReqUserInfo> apiRequest) {
        ReqUserInfo reqUserInfo = apiRequest.getData();
        if (null == reqUserInfo.getUid()) {
            throw new BizException(AssetsErrorEnum.USER_ID_NULL);
        }
        userAssetsRepository.initAllCount(reqUserInfo.getUid());
        TbUserAssetsExample tbUserAssetsExample = new TbUserAssetsExample();
        TbUserAssetsExample.Criteria criteria = tbUserAssetsExample.createCriteria();
        criteria.andUidEqualTo(reqUserInfo.getUid());
        if (null != reqUserInfo.getAssetsType()) {
            criteria.andAssetsTypeEqualTo(reqUserInfo.getAssetsType());
        }
        List<TbUserAssets> tbUserAssetsList = tbUserAssetsMapper.selectByExample(tbUserAssetsExample);
        return APIResponse.returnSuccess(tbUserAssetsList);

    }


    @Override
    @Valid
    @Transactional(rollbackFor = Exception.class)
    public APIResponse<BaseEnum> freezeOrder(APIRequest<ReqFreezeOrder> apiRequest) {
        logger.info("下单冻结资产"+GsonUtils.toJson(apiRequest));
        ReqFreezeOrder reqFreezeOrder=apiRequest.getData();
        //优惠券冻结
        if(null!=reqFreezeOrder.getReqCoupon()){
            APIRequest<ReqCoupon> couponAPIRequest=new APIRequest<ReqCoupon>();
            couponAPIRequest.setData(reqFreezeOrder.getReqCoupon());
            APIResponse<RespCoupon> respCouponAPIResponse=couponService.freezeCoupon(couponAPIRequest);
            //如果有用鸟蛋金额要减掉
            if(respCouponAPIResponse.isRet()&&null!=reqFreezeOrder.getReqUserAccumulateModifyBatch()){
                ReqUserAccumulateModifyBatch reqUserAccumulateModifyBatch=reqFreezeOrder.getReqUserAccumulateModifyBatch();
                reqUserAccumulateModifyBatch.setOrderAmount(reqUserAccumulateModifyBatch.getOrderAmount().subtract(respCouponAPIResponse.getData().getCouponAmount()));
                reqFreezeOrder.setReqUserAccumulateModifyBatch(reqUserAccumulateModifyBatch);
            }else if(!respCouponAPIResponse.isRet()){
                return APIResponse.returnFail(respCouponAPIResponse.getErrmsg());
            }
        }
        //鸟蛋冻结
        if(null!=reqFreezeOrder.getReqUserAccumulateModifyBatch()){
            APIRequest<ReqUserAccumulateModifyBatch> accumulateAPIRequest=new APIRequest<ReqUserAccumulateModifyBatch>();
            accumulateAPIRequest.setData(reqFreezeOrder.getReqUserAccumulateModifyBatch());
            APIResponse<List<RespUserAccumulateModify>> apiResponse=freezeAccumulateBatch(accumulateAPIRequest);
            if(!apiResponse.isRet()){
                //回滚
                throw new BizException(apiResponse.getErrmsg());
            }
        }
        logger.info("冻结完成");
        return APIResponse.returnSuccess();
    }

    @Override
    public APIResponse<BaseEnum> unfreezeSuccess(APIRequest<ReqUnfreezeOrder> apiRequest) {
        ReqUnfreezeOrder reqFreezeOrder=apiRequest.getData();
        //优惠券解冻
        if(null!=reqFreezeOrder.getReqCoupon()){
            APIRequest<ReqCoupon> couponAPIRequest=new APIRequest<ReqCoupon>();
            couponAPIRequest.setData(reqFreezeOrder.getReqCoupon());
            couponService.unfreezeCouponSuccess(couponAPIRequest);
        }
        if(null!=reqFreezeOrder.getReqUnfreeze()){
            APIRequest<ReqUnfreeze> accumulateAPIRequest=new APIRequest<ReqUnfreeze>();
            accumulateAPIRequest.setData(reqFreezeOrder.getReqUnfreeze());
            unfreezeAccumulateSuccess(accumulateAPIRequest);
        }
        return APIResponse.returnSuccess();
    }

    @Override
    public APIResponse<BaseEnum> unfreezeFail(APIRequest<ReqUnfreezeOrder> apiRequest) {
        ReqUnfreezeOrder reqFreezeOrder=apiRequest.getData();
        //优惠券解冻
        if(null!=reqFreezeOrder.getReqCoupon()){
            reqFreezeOrder.getReqCoupon().setActualAmount(null);
            reqFreezeOrder.getReqCoupon().setOrderState(null);
            APIRequest<ReqCoupon> couponAPIRequest=new APIRequest<ReqCoupon>();
            couponAPIRequest.setData(reqFreezeOrder.getReqCoupon());
            couponService.unfreezeCouponFail(couponAPIRequest);
        }
        if(null!=reqFreezeOrder.getReqUnfreeze()){
            APIRequest<ReqUnfreeze> accumulateAPIRequest=new APIRequest<ReqUnfreeze>();
            accumulateAPIRequest.setData(reqFreezeOrder.getReqUnfreeze());
            unfreezeAccumulateFail(accumulateAPIRequest);
        }
        return APIResponse.returnSuccess();
    }

    @Override
    @Transactional
    @Valid
    public APIResponse<List<TbUserAssets>> refundSubmit(APIRequest<ReqRefund> apiRequest) {
        logger.info("资产系统refundSubmit方法开始"+apiRequest.toString());
        ReqRefund reqRefund=apiRequest.getData();
        //积分退款冻结
        ReqAccumulateRefund reqAccumulateRefund=reqRefund.getReqAccumulateRefund();
        if(null!=reqAccumulateRefund){
            utilAccumulateService.refundAccumulateSubmit(reqAccumulateRefund);
        }
        //优惠券退款冻结
        ReqCouponRefund reqCouponRefund=reqRefund.getReqCouponRefund();
        if(reqCouponRefund!=null){
            utilCouponService.refundCouponSubmit(reqCouponRefund);
        }
        logger.info("资产系统refundSubmit方法结束"+apiRequest.toString());
        return APIResponse.returnSuccess();
    }

    @Override
    @Transactional
    @Valid
    public APIResponse<List<TbUserAssets>> refundSuccess(APIRequest<ReqRefund> apiRequest) {
        logger.info("资产系统refundSuccess方法开始"+apiRequest.toString());
        ReqRefund reqRefund=apiRequest.getData();
        //积分退款成功
        ReqAccumulateRefund reqAccumulateRefund=reqRefund.getReqAccumulateRefund();
        if(null!=reqAccumulateRefund){
            utilAccumulateService.refundAccumulateSuccess(reqAccumulateRefund);
        }
        //优惠券退款成功
        ReqCouponRefund reqCouponRefund=reqRefund.getReqCouponRefund();
        if(reqCouponRefund!=null){
            utilCouponService.refundCouponSuccess(reqCouponRefund);
        }
        logger.info("资产系统refundSuccess方法结束"+apiRequest.toString());
        return APIResponse.returnSuccess();
    }

    @Override
    @Transactional
    @Valid
    public APIResponse<List<TbUserAssets>> refundFail(APIRequest<ReqRefund> apiRequest) {
        ReqRefund reqRefund=apiRequest.getData();
        //积分退款失败
        ReqAccumulateRefund reqAccumulateRefund=reqRefund.getReqAccumulateRefund();
        if(null!=reqAccumulateRefund){
            utilAccumulateService.refundAccumulateFail(reqAccumulateRefund);
        }
        //优惠券退款失败
        ReqCouponRefund reqCouponRefund=reqRefund.getReqCouponRefund();
        if(reqCouponRefund!=null){
            utilCouponService.refundCouponFail(reqCouponRefund);
        }
        return APIResponse.returnSuccess();
    }

    @Override
    @Transactional
    @Valid
    public APIResponse batchModifyEgg(APIRequest<List<ReqUserAccumulateModify>> apiRequest) {
        logger.info("批量添加鸟蛋mq"+ GsonUtils.toJson(apiRequest.getData()));
        List<Integer> uidList=new ArrayList<Integer>();
        List<ReqBatchAddEgg> reqBatchAddEggList=new ArrayList<ReqBatchAddEgg>();
        ReqBatchAddEgg reqBatchAddEgg=null;
        //判断systemCode+businessCode+assetsType是否存在
        TbAccumulateRuleExample tbAccumulateRuleExample = new TbAccumulateRuleExample();
        tbAccumulateRuleExample.createCriteria().andSystemCodeEqualTo(apiRequest.getData().get(0).getSystemCode())
                .andBusinessCodeEqualTo(apiRequest.getData().get(0).getBusinessCode())
                .andAssetsTypeEqualTo(apiRequest.getData().get(0).getAssetsType());
        List<TbAccumulateRule> tbAccumulateRuleList = tbAccumulateRuleMapper.selectByExample(tbAccumulateRuleExample);
        if (tbAccumulateRuleList.isEmpty()) {
            throw new BizException(AssetsErrorEnum.ASSETS_RULE_RECORD_DO_NOT_EXISTS);
        }
        for(ReqUserAccumulateModify reqUserAccumulateModify:apiRequest.getData()){
            userAssetsRepository.initAllCount(reqUserAccumulateModify.getUid());
            uidList.add(reqUserAccumulateModify.getUid());
            reqBatchAddEgg=new ReqBatchAddEgg();
            reqBatchAddEgg.setUid(reqUserAccumulateModify.getUid());
            reqBatchAddEgg.setAccumulate(reqUserAccumulateModify.getAccumulate());
            reqBatchAddEggList.add(reqBatchAddEgg);
        }
        etbUserAssetsMapper.batchAddEggClub(reqBatchAddEggList);
        TbUserAssetsExample tbUserAssetsExample=new TbUserAssetsExample();
        tbUserAssetsExample.createCriteria().andUidIn(uidList).andAssetsTypeEqualTo(AssetsType.ASSETS_EGGS.id.byteValue());
        //一次性获取用户更新完后数据
        List<TbUserAssets> tbUserAssetsList=tbUserAssetsMapper.selectByExample(tbUserAssetsExample);
        logger.info("批量更新用户鸟蛋数量完成");
        //把鸟蛋数据放到MAP中
        Map<Integer,Object> tbUserAssetsMap = new HashMap<Integer,Object>();
        for(TbUserAssets tbUserAssets:tbUserAssetsList){
            tbUserAssetsMap.put(tbUserAssets.getUid(),tbUserAssets);
        }
        List<TbUserEggsAccumulateHistory> tbUserEggsAccumulateHistoryList=new ArrayList<TbUserEggsAccumulateHistory>();
        TbUserEggsAccumulateHistory tbUserEggsAccumulateHistory = null;
        TbUserAssets tbUserAssets = null;
        for(ReqUserAccumulateModify reqUserAccumulateModify:apiRequest.getData()){
            tbUserAssets = (TbUserAssets)tbUserAssetsMap.get(reqUserAccumulateModify.getUid());
            String serialNumber = CommonUtils.generateBusinessOrderNo(Constants.ASSETS_SYSTEM, reqUserAccumulateModify.getUid());
            tbUserEggsAccumulateHistory = new TbUserEggsAccumulateHistory();
            try{
                APIResponse<RespUserInfoBase> respUserInfoBaseAPIResponse=userServiceFacade.queryUserInfo(reqUserAccumulateModify.getUid());
                logger.info("获取用户信息"+ GsonUtils.toJson(respUserInfoBaseAPIResponse));
                if(null != respUserInfoBaseAPIResponse.getData()){
                    tbUserEggsAccumulateHistory.setNickName(respUserInfoBaseAPIResponse.getData().getNickName());
                    tbUserEggsAccumulateHistory.setMobile(respUserInfoBaseAPIResponse.getData().getMobile());
                }
            }catch (Exception e){

            }
            tbUserEggsAccumulateHistory.setUid(reqUserAccumulateModify.getUid());
            tbUserEggsAccumulateHistory.setAccumulate(reqUserAccumulateModify.getAccumulate());
            tbUserEggsAccumulateHistory.setOpBefore(tbUserAssets.getAccumulate()-reqUserAccumulateModify.getAccumulate());
            tbUserEggsAccumulateHistory.setOpAfter(tbUserAssets.getAccumulate());
            tbUserEggsAccumulateHistory.setOpType(OpType.RECEIVE.id.byteValue());
            tbUserEggsAccumulateHistory.setBusinessCode(reqUserAccumulateModify.getBusinessCode());
            tbUserEggsAccumulateHistory.setSystemCode(reqUserAccumulateModify.getSystemCode());
            tbUserEggsAccumulateHistory.setStatus(StatusType.EFFECTIVE.id.byteValue());
            tbUserEggsAccumulateHistory.setPayReceive(reqUserAccumulateModify.getPayReceive());
            tbUserEggsAccumulateHistory.setInfo(reqUserAccumulateModify.getInfo());
            tbUserEggsAccumulateHistory.setSerialNumber(serialNumber);
            tbUserEggsAccumulateHistory.setReceiver(reqUserAccumulateModify.getReceiver());
            tbUserEggsAccumulateHistory.setpDescribe(tbAccumulateRuleList.get(0).getpDescribe());
            tbUserEggsAccumulateHistoryList.add(tbUserEggsAccumulateHistory);
        }
        logger.info("批量添加鸟蛋历史明细数据"+ GsonUtils.toJson(tbUserEggsAccumulateHistoryList));
        //批量更新历史表
        eTbUserEggsAccumulateHistoryMapper.batchAdd(tbUserEggsAccumulateHistoryList);
        return APIResponse.returnSuccess();
    }


    private void insertAccumulateHistory(Byte opType, ReqUserAccumulateModifyBatch reqUserAccumulateModifyBatch, AccumulateAssets accumulateAssets) {
        String serialNumber = CommonUtils.generateBusinessOrderNo(Constants.ASSETS_SYSTEM, reqUserAccumulateModifyBatch.getUid());
        if (accumulateAssets.getAssetsType() == AssetsType.ASSETS_EGGS.id.byteValue()) {
            //鸟蛋历史记录
            TbUserEggsAccumulateHistory tbUserEggsAccumulateHistory = new TbUserEggsAccumulateHistory();
            try {
                APIResponse<RespUserInfoBase> respUserInfoBaseAPIResponse = userServiceFacade.queryUserInfo(reqUserAccumulateModifyBatch.getUid());
                RespUserInfoBase respUserInfoBase = respUserInfoBaseAPIResponse.getData();
                if (respUserInfoBaseAPIResponse.isRet() && null != respUserInfoBase) {
                    tbUserEggsAccumulateHistory.setMobile(respUserInfoBase.getMobile());
                    tbUserEggsAccumulateHistory.setNickName(respUserInfoBase.getNickName());
                }
            } catch (Exception e) {
                //ignore error
            }
            tbUserEggsAccumulateHistory.setUid(reqUserAccumulateModifyBatch.getUid());
            tbUserEggsAccumulateHistory.setAccumulate(accumulateAssets.getAccumulate());
            tbUserEggsAccumulateHistory.setOpType(opType);
            tbUserEggsAccumulateHistory.setBusinessId(reqUserAccumulateModifyBatch.getBusinessId());
            tbUserEggsAccumulateHistory.setBusinessCode(reqUserAccumulateModifyBatch.getBusinessCode());
            tbUserEggsAccumulateHistory.setBusinessNo(reqUserAccumulateModifyBatch.getBusinessNo());
            tbUserEggsAccumulateHistory.setSystemCode(reqUserAccumulateModifyBatch.getSystemCode());
            tbUserEggsAccumulateHistory.setStatus(reqUserAccumulateModifyBatch.getStatus() == null ? StatusType.EFFECTIVE.id.byteValue() : reqUserAccumulateModifyBatch.getStatus());
            tbUserEggsAccumulateHistory.setExpireTime(reqUserAccumulateModifyBatch.getExpireTime());
            tbUserEggsAccumulateHistory.setReceiver(reqUserAccumulateModifyBatch.getReceiver());
            tbUserEggsAccumulateHistory.setPayReceive(reqUserAccumulateModifyBatch.getPayReceive());
            tbUserEggsAccumulateHistory.setInfo(reqUserAccumulateModifyBatch.getInfo());
            tbUserEggsAccumulateHistory.setSerialNumber(serialNumber);
            tbUserEggsAccumulateHistory.setBatchNo(0);
            tbUserEggsAccumulateHistory.setpDescribe(reqUserAccumulateModifyBatch.getDescribe());
            eggsAccumulateHistoryRepository.insertAccumulateHistory(tbUserEggsAccumulateHistory);
        } else if (accumulateAssets.getAssetsType() == AssetsType.ASSETS_SHELL.id.byteValue()) {
            //鸟壳历史记录
            TbUserShellAccumulateHistory tbUserShellAccumulateHistory = new TbUserShellAccumulateHistory();
            tbUserShellAccumulateHistory.setUid(reqUserAccumulateModifyBatch.getUid());
            tbUserShellAccumulateHistory.setAccumulate(accumulateAssets.getAccumulate());
            tbUserShellAccumulateHistory.setOpType(opType);
            tbUserShellAccumulateHistory.setBusinessId(reqUserAccumulateModifyBatch.getBusinessId());
            tbUserShellAccumulateHistory.setBusinessCode(reqUserAccumulateModifyBatch.getBusinessCode());
            tbUserShellAccumulateHistory.setBusinessNo(reqUserAccumulateModifyBatch.getBusinessNo());
            tbUserShellAccumulateHistory.setSystemCode(reqUserAccumulateModifyBatch.getSystemCode());
            tbUserShellAccumulateHistory.setStatus(reqUserAccumulateModifyBatch.getStatus() == null ? StatusType.EFFECTIVE.id.byteValue() : reqUserAccumulateModifyBatch.getStatus());
            tbUserShellAccumulateHistory.setExpireTime(reqUserAccumulateModifyBatch.getExpireTime());
            tbUserShellAccumulateHistory.setReceiver(reqUserAccumulateModifyBatch.getReceiver());
            tbUserShellAccumulateHistory.setPayReceive(reqUserAccumulateModifyBatch.getPayReceive());
            tbUserShellAccumulateHistory.setInfo(reqUserAccumulateModifyBatch.getInfo());
            tbUserShellAccumulateHistory.setSerialNumber(serialNumber);
            shellAccumulateHistoryRepository.insertAccumulateHistory(tbUserShellAccumulateHistory);
        }
    }


}
